class LoadingUI extends egret.Sprite {

    public loading_bg: egret.Bitmap;
    public loadingMask:egret.Bitmap;
    public loading:egret.Bitmap;
    public loading_mv:egret.Bitmap;
    public mainContainer:egret.DisplayObjectContainer;
    private load_mv:egret.MovieClip;
    private textfile:egret.TextField;
    public constructor() {
        super();
        this.createView();
    }



    private createView(): void {
        this.mainContainer=new egret.DisplayObjectContainer();
        this.addChild(this.mainContainer);
        this.textfile = new egret.TextField();
        this.textfile.textAlign = 'center';
        this.textfile.width = utils.CoreData.instance.screenW;
        this.textfile.textColor = 0xe8232d;
        this.textfile.y = 700;
        this.textfile.size = 20;
        var data = RES.getRes('load_new_json');
        var fire_png = RES.getRes('load_new_png');
        this.load_mv = this.createMovieClip(data,fire_png,"load_new");
        this.load_mv.gotoAndPlay(0, -1);
        this.load_mv.frameRate = 12;
        if(utils.CoreData.instance.screenH > 1138){
            // this.load_mv.y = (utils.CoreData.instance.screenH - 1138)*0.5;
        }
        
        this.load_mv.x = 170;
        this.load_mv.y = 350;
        this.mainContainer.addChild(this.load_mv);
        this.mainContainer.addChild(this.textfile);
        
    }

    public setProgress(current, total): void {
        // this.loadingMask.width=this.loading.width*current / total;
        // this.loading_mv.x = this.loadingMask.width;

        this.textfile.text = Math.floor((current / total)*100) + '%';
    }

    private createMovieClip(data:any,texture:egret.Texture,names:string):egret.MovieClip {
        //创建动画工厂
        var mcDataFactory:egret.MovieClipDataFactory = new egret.MovieClipDataFactory(data,texture);
        //创建 MovieClip，将工厂生成的 MovieClipData 传入参数
        var mc:egret.MovieClip = new egret.MovieClip(mcDataFactory.generateMovieClipData(names));
        return mc;
    }

    public ClearMv(){
        if(this.load_mv){
            this.load_mv.stop();

            if(this.load_mv.parent)
                this.load_mv.parent.removeChild(this.load_mv);
        }
    }
}
